package com.shenzhenai.composebasic.components

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Image
import androidx.compose.material3.Icon
import androidx.compose.material3.LeadingIconTab
import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

/**
 * @author huangzehui
 * @date 14/9/2025 下午9:58 周日
 * @description
 *
 *
 * TabRow 用法
 * https://www.bilibili.com/video/BV1eY411G74F?vd_source=e07cc8cc94eb22bd76722071b03cd199&spm_id_from=333.788.videopod.sections
 */


@Composable
fun TabSample() {

    var selectedTabIndex by remember {
        mutableStateOf(0)
    }

    Column {
        TabRow(selectedTabIndex = selectedTabIndex) {
            Text(text = "Tab1", textAlign = TextAlign.Center, modifier = Modifier
                .padding(8.dp)
                .clickable {
                    selectedTabIndex = 0
                })
            Text(text = "Tab2", textAlign = TextAlign.Center, modifier = Modifier
                .padding(8.dp)
                .clickable {
                    selectedTabIndex = 1
                })
            Text(text = "Tab3", textAlign = TextAlign.Center, modifier = Modifier
                .padding(8.dp)
                .clickable {
                    selectedTabIndex = 2
                })
        }

        Text(text = "current index = ${selectedTabIndex}")
    }
}


@Composable
fun TabSample1() {
    var selectedTabIndex by remember {
        mutableStateOf(0)
    }

    Column {
        TabRow(selectedTabIndex = selectedTabIndex) {
            Tab(selected = selectedTabIndex == 0,
                selectedContentColor = Color.Red,
                unselectedContentColor = Color.Gray,
                onClick = {
                    selectedTabIndex = 0
                },
                icon = {
                    Icon(
                        imageVector = Icons.Default.Image,
                        contentDescription = null
                    )
                },
                text = {
                    Text(text = "Tab0")
                })

            Tab(selected = selectedTabIndex == 1,
                selectedContentColor = Color.Red,
                unselectedContentColor = Color.Gray,
                onClick = {
                    selectedTabIndex = 1
                },
                icon = {
                    Icon(
                        imageVector = Icons.Default.Image,
                        contentDescription = null
                    )
                },
                text = {
                    Text(text = "Tab1")
                }
            )
            Tab(selected = selectedTabIndex == 2,
                selectedContentColor = Color.Red,
                unselectedContentColor = Color.Gray, onClick = {
                    selectedTabIndex = 2
                },
                icon = {
                    Icon(
                        imageVector = Icons.Default.Image,
                        contentDescription = null
                    )
                },
                text = {
                    Text(text = "Tab2")
                })


            LeadingIconTab(
                selected = selectedTabIndex == 3,
                selectedContentColor = Color.Red,
                unselectedContentColor = Color.Gray,
                onClick = {
                    selectedTabIndex = 3
                },
                icon = {
                    Icon(
                        imageVector = Icons.Default.Image,
                        contentDescription = null
                    )
                },
                text = {
                    Text(text = "Tab3")
                })
        }

        Text(text = "current index = ${selectedTabIndex}")
    }
}

@Preview
@Composable
fun TabSamplePreview() {
//    TabSample()
    TabSample1()
}